package org.jks.model;

import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.GenericGenerator;

import com.google.gson.annotations.Expose;

@Entity
@Table(name = "Device")
public class Device {
	@Id
	@GeneratedValue(generator = "increment")
	@GenericGenerator(name = "increment", strategy = "increment")
	@Expose
	private long Id;
	@Column(length = 64, nullable = false, unique = true)
	@Expose
	private String No;
	@Column(length = 100, nullable = false, unique = true)
	@Expose
	private String TdCode;
	@ManyToOne
	@JoinColumn(name = "Type", referencedColumnName = "Id", nullable = false)
	@Expose
	private DeviceType Type;
	/**
	 * 设备品牌
	 */
	@Column(length = 64)
	@Expose
	private String Brand;
	/**
	 * 设备厂家
	 */
	@Column(length = 128)
	@Expose
	private String Manufacturers;
	/**
	 * 设备型号
	 */
	@Column(length = 64)
	@Expose
	private String Model;
	@Expose
	@Temporal(TemporalType.TIMESTAMP)
	private Date OperationTime;
	@ManyToOne
	@JoinColumn(name = "CurrentStatus", referencedColumnName = "Id", nullable = false)
	@Expose
	private DeviceStatus CurrentStatus;
	@Column(name = "ImgPath", length = 128)
	@Expose
	private String ImgPath;
	/**
	 * 是否为备品
	 */
	@Column(name = "IsSparePart")
	@Expose
	private boolean IsSparePart;
	@ManyToOne
	@JoinColumn(name = "Flight", referencedColumnName = "Id", nullable = true)
	@Expose
	private Flight Flight;

	@ManyToOne
	@JoinColumn(name = "Work", referencedColumnName = "Id")
	private Work Work;

	@OneToMany(mappedBy = "Device", fetch = FetchType.LAZY, cascade = { CascadeType.ALL }, orphanRemoval = true)
	@Expose
	private List<DeviceRe> DeviceRe; // 飞行履历表

	public long getId() {
		return Id;
	}

	public void setId(long id) {
		Id = id;
	}

	public String getTdCode() {
		return TdCode;
	}

	public void setTdCode(String tdCode) {
		TdCode = tdCode;
	}

	public String getNo() {
		return No;
	}

	public void setNo(String no) {
		No = no;
	}

	public DeviceType getType() {
		return Type;
	}

	public void setType(DeviceType type) {
		Type = type;
	}

	public String getBrand() {
		return Brand;
	}

	public void setBrand(String brand) {
		Brand = brand;
	}

	public String getManufacturers() {
		return Manufacturers;
	}

	public void setManufacturers(String manufacturers) {
		Manufacturers = manufacturers;
	}

	public String getModel() {
		return Model;
	}

	public void setModel(String model) {
		Model = model;
	}

	public Date getOperationTime() {
		return OperationTime;
	}

	public void setOperationTime(Date operationTime) {
		OperationTime = operationTime;
	}

	public DeviceStatus getCurrentStatus() {
		return CurrentStatus;
	}

	public void setCurrentStatus(DeviceStatus currentStatus) {
		CurrentStatus = currentStatus;
	}

	public String getImgPath() {
		return ImgPath;
	}

	public void setImgPath(String imgPath) {
		ImgPath = imgPath;
	}

	public boolean isIsSparePart() {
		return IsSparePart;
	}

	public void setIsSparePart(boolean isSparePart) {
		IsSparePart = isSparePart;
	}

	public Flight getFlight() {
		return Flight;
	}

	public void setFlight(Flight flight) {
		Flight = flight;
	}

	public Work getWork() {
		return Work;
	}

	public void setWork(Work work) {
		Work = work;
	}

	public List<DeviceRe> getDeviceRe() {
		return DeviceRe;
	}

	public void setDeviceRe(List<DeviceRe> deviceRe) {
		DeviceRe = deviceRe;
	}

	@Override
	public String toString() {
		return "Device [Id=" + Id + ", No=" + No + ", TdCode=" + TdCode
				+ ", Type=" + Type + ", Brand=" + Brand + ", Manufacturers="
				+ Manufacturers + ", Model=" + Model + ", OperationTime="
				+ OperationTime + ", CurrentStatus=" + CurrentStatus
				+ ", ImgPath=" + ImgPath + ", IsSparePart=" + IsSparePart + "]";
	}

}
